#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:do_gene2.py
# author: 马国鑫
# datetime:2022/4/7 18:07
# software: PyCharm

"""
this is function  description 
"""

# 生成器案例：斐波那契数列

"""
    创建生成器，实现斐波那契数列
        1.定义变量保存第一列和第二列数据
        2.定义变量保存当前生成的位置
        3.循环生成数据，条件当前列数小于总列数
        4.保存a的值
        5.修改a和b的值
        6.返回a的值
    yield两个作用： 
    （1）充当return
    （2）能够保存当前程序的状态
     (3)next的时候，可以从上次yield的位置下次继续执行
"""


# def fibnacci(n):
#     a = 1
#     b = 1
#     current_index = 0
#     while current_index < n:
#         data = a
#         a, b = b, a + b
#         current_index += 1
#         yield data  # 通过生成器去返回a的值
#
#
# if __name__ == '__main__':
#     fib = fibnacci(5)
#     for value in fib:
#         print(value, end=' ')



def fibnacci(n):
    a = 1
    b = 1
    current_index = 0
    while current_index < n:
        data = a
        a,b = b, a+b
        current_index += 1
        params = yield data
        print("params---->", params)


if __name__ == '__main__':
    fib = fibnacci(5)
    value = fib.send(None)
    print(value)
    value = fib.send("abc")
    print(value)

